<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>

        // 获取cookie
        //    获取到的是字符串    名称=内容; 名称=内容; 名称=内容;


        console.log(document.cookie);


        // 显示y1对应的内容

        let cookies = document.cookie;

        // 注意分号后面有个空格
        let arr = cookies.split('; ');
        console.log(arr);   // ['y1=cc' , 'y2=yy']

        // arr = arr.map(v => v.split('='));

        // console.log(arr);    // 二维数组

        arr = arr.map(v => {
            let val = v.split('=');
            const obj = {};
            obj.name = val[0];
            obj.content = val[1];
            return obj
        })

        console.log(arr);     // [{name:'y1' , content: 'cc'} , {name : 'y2' , content : 'yy'}]


        // 找y1
        const res = arr.filter(v => {
            return v.name === 'y1'
        })
        console.log(res);    // [{name:'y1' , content: 'cc'}]

        const name = res[0].content;
        console.log(name);




    </script>

</body>

</html>